﻿using System;
using System.Collections.Generic;
using System.Text;
using Vortex.Input;

namespace Vortex.SceneFramework {

	/// <summary>
	/// Implements some common stuff for keyboard and mouse input event infos
	/// </summary>
	public abstract class InputEventInfo : EventInfo {
		private KeyStates _keyStates;

		/// <summary>
		/// Initializes a new instance of the <see cref="InputEventInfo"/> class.
		/// </summary>
		/// <param name="eventTarget">The event target element.</param>
		/// <param name="keyStates">The key states at the moment of event.</param>
		protected InputEventInfo(Node eventTarget, KeyStates keyStates)
			: base(eventTarget) {
			_keyStates = keyStates;
		}

		/// <summary>
		/// Gets important keys pressed state when event has been occurred (Ctrl, Shift, Alt + mouse buttons)
		/// </summary>
		/// <value>The key states flags.</value>
		public KeyStates KeyStates {
			get { return _keyStates; }
		}

		#region KeyStates helpers

		/// <summary>
		/// Gets a value indicating whether left mouse button is down for this event.
		/// </summary>
		/// <value>
		/// 	<c>true</c> if left button is down for this event; otherwise, <c>false</c>.
		/// </value>
		public bool IsLeftButtonDown {
			get { return HasStates(KeyStates.LeftButton); }
		}

		/// <summary>
		/// Gets a value indicating whether right mouse button is down for this event.
		/// </summary>
		/// <value>
		/// 	<c>true</c> if right button is down for this event; otherwise, <c>false</c>.
		/// </value>
		public bool IsRightButtonDown {
			get { return HasStates(KeyStates.RightButton); }
		}


		/// <summary>
		/// Gets a value indicating whether middle mouse button is down for this event.
		/// </summary>
		/// <value>
		/// 	<c>true</c> if middle button is down for this event; otherwise, <c>false</c>.
		/// </value>
		public bool IsMiddleButtonDown {
			get { return HasStates(KeyStates.MiddleButton); }
		}


		/// <summary>
		/// Gets a value indicating whether any control button is down for this event.
		/// </summary>
		/// <value>
		/// 	<c>true</c> if any control button is down for this event; otherwise, <c>false</c>.
		/// </value>
		public bool IsControlDown {
			get { return HasStates(KeyStates.Control); }
		}

		/// <summary>
		/// Gets a value indicating whether any shift button is down for this event.
		/// </summary>
		/// <value>
		/// 	<c>true</c> if any shift button is down for this event; otherwise, <c>false</c>.
		/// </value>
		public bool IsShiftDown {
			get { return HasStates(KeyStates.Shift); }
		}

		/// <summary>
		/// Gets a value indicating whether any alt button is down for this event.
		/// </summary>
		/// <value>
		/// 	<c>true</c> if any alt button is down for this event; otherwise, <c>false</c>.
		/// </value>
		public bool IsAltDown {
			get { return HasStates(KeyStates.Alt); }
		}

		/// <summary>
		/// Determines whether the all of specified key states are set for this event.
		/// </summary>
		/// <param name="keyStates">The key states to check.</param>
		/// <returns>
		/// 	<c>true</c> if the all of specified key states are set; otherwise, <c>false</c>.
		/// </returns>
		public bool HasStates(KeyStates keyStates) {
			return (_keyStates & keyStates) == keyStates;
		}

		#endregion

	}
}
